<template>
	<view class="cash">
		<view class="pageHeader dFlex jStart_aCenter" :style="{'padding-top': pageStatus + 'px'}">
			<view class="backIcon imgPublic" @tap.stop='back'>
				<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/back3.png" mode='widthFix'></image>
			</view>
			<view class='title'>余额提现</view>
			<view class="backIcon imgPublic"></view>
		</view>
		<view class="container">
			<view class="tixian">
				<view class="part1">
					<view class="tit">提现金额</view>
					<view class="partIpt dFlex jStart_aCenter">
						<view class="ipt">
							<input type="number" v-model="money" placeholder="请输入提现金额">
						</view>
					</view>
					<view class="toast dFlex jBetween_aCenter">
						<text>余额: ￥{{wallet?wallet:'0.00'}}</text>
						<text class='all' @click="money = wallet">全部提现</text>
					</view>
				</view>
			</view>
			<view class="shopMsg">
				<view class="orderLine dFlex jBetween_aCenter" @tap='changePay("0")'>
					<view class="lineTit dFlex jStart_aCenter">
						<text>微信</text>
					</view>
					<view class="lineVal dFlex jEnd_aCenter">
						<view class="statusIcon imgPublic">
							<image v-if="paytype != '0'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/unsel.png" mode="widthFix"></image>
							<image v-if="paytype == '0'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/sel2.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
				<view class="orderLine dFlex jBetween_aCenter" @tap='changePay("1")'>
					<view class="lineTit dFlex jStart_aCenter">
						<text>支付宝</text>
					</view>
					<view class="lineVal dFlex jEnd_aCenter">
						<view class="statusIcon imgPublic">
							<image v-if="paytype != '1'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/unsel.png" mode="widthFix"></image>
							<image v-if="paytype == '1'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/sel2.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="tixian">
				<view class="part1">
					<view class="tit">收款码</view>
					<view class="partIpt dFlex jStart_aCenter">
						<view class="upTool imgPublic" @tap='upImg'>
							<image v-if='payment_code' :src="payment_code" mode="widthFix"></image>
							<image v-if='!payment_code' src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/upTool.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view :class='["btns",device == "ios"?"ios_padding":""]'>
			<view class="btn" @tap='subInfo'>立即提现</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				device:getApp().globalData.platform,
				pageHeader:getApp().globalData.pageHeader,
				pageStatus:getApp().globalData.pageStatus,
				wallet:'',
				paytype:'0',
				money:'',
				payment_code:'',
			};
		},
		onShow(){
			this.initUser();
		},
		methods:{
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			changePay(type){
				this.paytype = type;
			},
			upImg(){
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //从相册选择
					success:(res)=>{
						if(res.tempFilePaths.length){
							res.tempFilePaths.map((item,index)=>{
								this.tool.upImg(item).then(thumb=>{
									if(thumb){
										this.payment_code = thumb.fullurl;
									}
								}).catch(err=>{
									console.log(err);
								})
							})
						}
					},
					fail:(err)=>{
						uni.showToast({
							title:"图片选择失败",
							icon:"none"
						})
					},
					complete:()=>{
						
					},
				})
			},
			// 获取用户信息
			initUser(){
				this.tool.getData('/api/user/info',{},'',this).then(res=>{
					if(res){
						this.wallet = res.money;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 提交提现信息
			subInfo(){
				if(!this.money){
					uni.showToast({
						title:'请输入提现金额',
						icon:'none'
					})
					return
				}
				if(parseFloat(this.money)>parseFloat(this.wallet)){
					uni.showToast({
						title:'余额不足',
						icon:'none'
					})
					return
				}
				if(this.money.indexOf('.') > -1){
					uni.showToast({
						title:'提现金额必须是整数',
						icon:'none'
					})
					return
				}
				if(!this.payment_code){
					uni.showToast({
						title:'请上传收款码图片',
						icon:'none'
					})
					return
				}
				this.tool.getData('/api/user/withdrawcon',{
					money:this.money,
					type:this.paytype,
					payment_code:this.payment_code,
				}).then(res=>{
					console.log(res);
					if(res){
						uni.showToast({
							title:'提现申请已提交',
							icon:"success"
						})
						setTimeout(()=>{
							this.back();
						},1650)
					}
				}).catch(err=>{
					console.log(err);
				})
			}
		}
	}
</script>

<style lang="scss">
	.ios_padding{
		padding-bottom:env(safe-area-inset-bottom);
	}
	.cash{
		width: 100%;
		.btns{
			.btn{
				width: 100%;
				padding: 12px 0;
				border-radius: 5px;
				background: #FF5000;
				text-align: center;
				color: white;
			}
			width: 100%;
			position: fixed;
			left:0;
			bottom: 0;
		}
		.container{
			width: 100%;
			.shopMsg{
				width: calc(100% - 24px);
				border-radius: 8px;
				padding: 16px 12px;
				background: white;
				box-sizing: border-box;
				margin:0 auto;
				.orderLine{
					width: 100%;
					margin-bottom: 12px;
					color: #666666;
					.lineVal{
						.statusIcon{
							width: 44rpx;
							height:44rpx;
							margin-left: 12rpx;
							padding: 1px;
							box-sizing: border-box;
						}
						.toast{
							color: #999999;
						}
						.condition{
							width: max-content;
							padding: 4rpx 14rpx;
							color: #FF5000;
							background: rgba(255,240,232,0.39);
							border-radius: 4px;
						}
						.rightIcon{
							width: 20rpx;
							height: 20rpx;
							margin-left: 4rpx;
						}
					}
					.lineTit{
						width: max-content;
						text{
							color: #333333;
						}
					}
				}
				.orderLine:last-child{
					margin: 0;
				}
				.shopList{
					width: 100%;
					margin-bottom: 24px;
					.shopInfo{
						width: 100%;
						margin-bottom: 8px;
						.shopImg{
							width:80px;
							height: 80px;
							overflow: hidden;
							background: white;
							margin-right: 12px;
							border-radius: 8px;
						}
						.other{
							flex: 1;
							.price{
								font-size: 14px;
								color: #333333;
								margin-left: 5px;
							}
							.selSpec{
								font-size: 14px;
								color: #999999;
								margin: 10px 0;
							}
							.shopName{
								font-size: 15px;
							}
						}
					}
					.shopInfo:last-child{
						margin: 0;
					}
				}
			}
			.tixian{
				width: 100%;
				padding: 12px 4% 0;
				box-sizing: border-box;
				.part1{
					width: 100%;
					margin-bottom: 20px;
					.toast{
						color: #999999;
						margin-top: 12px;
						font-size:12px;
						.all{
							color:#FF5000;
						}
					}
					.partIpt{
						width: 100%;
						background: #ffffff;
						border-radius: 5px;
						box-shadow: 3.29px 6.74px 10px 0px rgba(87,85,217,0.10); 
						padding: 16px;
						box-sizing: border-box;
						margin-bottom: 12px;
						.upTool{
							width: 30%;
							margin: 0 auto;
						}
						.iptTit{
							width: 25%;
						}
						.ipt{
							flex: 1;
						}
					}
					.partIpt:last-child{
						margin: 0;
					}
					.tit{
						width: 100%;
						font-size: 16px;
						font-weight: bold;
						margin-bottom: 12px;
						.other{
							color: #1664FF;
							font-size: 14px;
							font-weight: 400;
						}
					}
				}
			}
		}
		.pageHeader{
			width: 100%;
			background: #FF5000;
			padding: 0 12px 10px;
			color: white;
			box-sizing: border-box;
		}
	}
</style>
